﻿using System;
using System.Collections.Generic;
using System.Text;

namespace EmbeddedSharp.Core.Function.Maths {

    /// <summary>
    /// Log
    /// </summary>
    [Function("log", "Gives the logarithm of base", "10~1000", "a==3")]
    public class LogNode : OperatorNode {
        public LogNode()
            : base() {
            base.Precedence = 3;
            base.Value = "~";
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }

        public override FuncNode GetReversedFunction(int index) {
            return new PowerNode();
        }

        public override object Evaluate() {
            double lr = Convert.ToDouble(Left.Evaluate());
            double rr = Convert.ToDouble(Right.Evaluate());

            return System.Math.Pow(lr, 1 / rr).ToString();
        }
    }
}
